import { FruitType } from '../types/game';

// 水果配置：从小到大的10种水果
export const FRUIT_TYPES: FruitType[] = [
  {
    id: 0,
    name: '樱桃',
    emoji: '🍒',
    color: '#ff6b6b',
    radius: 15,
    score: 1,
    mass: 0.3
  },
  {
    id: 1,
    name: '草莓',
    emoji: '🍓',
    color: '#ff8a95',
    radius: 18,
    score: 3,
    mass: 0.4
  },
  {
    id: 2,
    name: '葡萄',
    emoji: '🍇',
    color: '#9b59b6',
    radius: 22,
    score: 6,
    mass: 0.5
  },
  {
    id: 3,
    name: '橙子',
    emoji: '🍊',
    color: '#f39c12',
    radius: 26,
    score: 10,
    mass: 0.6
  },
  {
    id: 4,
    name: '苹果',
    emoji: '🍎',
    color: '#e74c3c',
    radius: 30,
    score: 15,
    mass: 0.7
  },
  {
    id: 5,
    name: '梨',
    emoji: '🍐',
    color: '#f1c40f',
    radius: 34,
    score: 21,
    mass: 0.8
  },
  {
    id: 6,
    name: '桃子',
    emoji: '🍑',
    color: '#ff9ff3',
    radius: 38,
    score: 28,
    mass: 0.9
  },
  {
    id: 7,
    name: '菠萝',
    emoji: '🍍',
    color: '#f39c12',
    radius: 42,
    score: 36,
    mass: 1.0
  },
  {
    id: 8,
    name: '椰子',
    emoji: '🥥',
    color: '#8d4004',
    radius: 46,
    score: 45,
    mass: 1.1
  },
  {
    id: 9,
    name: '西瓜',
    emoji: '🍉',
    color: '#27ae60',
    radius: 50,
    score: 55,
    mass: 1.2
  }
];

// 游戏配置
export const GAME_CONFIG = {
  // 游戏容器尺寸
  CONTAINER_WIDTH: 400,
  CONTAINER_HEIGHT: 600,
  WALL_THICKNESS: 10,
  
  // 物理引擎设置
  GRAVITY: 0.8,
  FRICTION: 0.001,
  RESTITUTION: 0.3,
  
  // 游戏逻辑
  DROP_LINE_Y: 100,
  GAME_OVER_LINE_Y: 80,
  MAX_FRUITS: 50,
  
  // 动画设置
  MERGE_ANIMATION_DURATION: 300,
  PARTICLE_COUNT: 15,
  PARTICLE_LIFE: 1000,
  
  // 投放设置
  DROP_COOLDOWN: 500,
  PREVIEW_FRUITS_COUNT: 5
};

// 获取随机初始水果（前5种）
export const getRandomInitialFruit = (): FruitType => {
  const availableFruits = FRUIT_TYPES.slice(0, GAME_CONFIG.PREVIEW_FRUITS_COUNT);
  return availableFruits[Math.floor(Math.random() * availableFruits.length)];
};

// 检查是否可以合成
export const canMerge = (fruit1: FruitType, fruit2: FruitType): boolean => {
  return fruit1.id === fruit2.id && fruit1.id < FRUIT_TYPES.length - 1;
};

// 获取合成后的水果
export const getMergedFruit = (fruitType: FruitType): FruitType | null => {
  if (fruitType.id >= FRUIT_TYPES.length - 1) return null;
  return FRUIT_TYPES[fruitType.id + 1];
};